package com.coding.controller;

import com.coding.base.pojo.BaseModel;
import com.coding.pojo.Tasklist;
import com.coding.service.TaskService;
import com.coding.service.TasklistService;
import com.wordnik.swagger.annotations.ApiOperation;
import com.wordnik.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @auther wangchenghao
 * @date 2020/7/27
 **/
@Controller
@ResponseBody
@RequestMapping("tasklist")
public class TaskListController {
    @Autowired
    TaskService taskService;
    @Autowired
    TasklistService tasklistService;

    @ApiOperation("搜索用户任务列表")
    @RequestMapping(value = "/getByUserId", method = {RequestMethod.GET})
    public BaseModel getbyuserid(@ApiParam("用户id") @RequestParam(value = "user_id", required = true) int user_id
    ) throws Exception {
        BaseModel model = new BaseModel();
        tasklistService.getlistbyid(user_id, model);
        return model;
    }

    @ApiOperation("搜索用户今日完成任务列表")
    @RequestMapping(value = "/getDayTaskList", method = {RequestMethod.GET})
    public BaseModel getDayFinish(@ApiParam("用户id") @RequestParam(value = "user_id", required = true) int user_id
    ) throws Exception {
        BaseModel model = new BaseModel();
        tasklistService.queryDayFinish(user_id, model);
        return model;
    }

    @ApiOperation("新增用户任务")
    @RequestMapping(value = "/insertUserTask", method = {RequestMethod.PUT})
    public BaseModel insertusertask(@ApiParam("任务id") @RequestParam(value = "task_id", required = true) int task_id,
                                    @ApiParam("用户id") @RequestParam(value = "user_id", required = true) int user_id,
                                    @ApiParam("more") @RequestParam(value = "tasklist_more", required = false) String tasklist_more
    ) throws Exception {
        BaseModel model = new BaseModel();
        tasklistService.inserttasklist(user_id, task_id, tasklist_more, model);
        return model;
    }

    @ApiOperation("用户任务完成byid")
    @RequestMapping(value = "/finishById", method = {RequestMethod.PUT})
    public BaseModel finishbyid(@ApiParam("任务id") @RequestParam(value = "task_id", required = true) int task_id,
                                @ApiParam("用户id") @RequestParam(value = "user_id", required = true) int user_id
    ) throws Exception {
        BaseModel model = new BaseModel();
        tasklistService.finishtask(user_id, task_id, model);
        return model;
    }

    @ApiOperation("用户任务完成byaccount")
    @RequestMapping(value = "/finishByAccount", method = {RequestMethod.PUT})
    public BaseModel finishbyaccount(@ApiParam("任务id") @RequestParam(value = "task_id", required = true) int task_id,
                                     @ApiParam("用户账户") @RequestParam(value = "user_account", required = true) String user_account
    ) throws Exception {
        BaseModel model = new BaseModel();
        tasklistService.finishtask(user_account, task_id, model);
        return model;
    }

    @ApiOperation("查询任务，可增加条件")
    @RequestMapping(value = "/getPageList", method = {RequestMethod.GET})
    public BaseModel getPageList(@ApiParam("任务id") @RequestParam(value = "task_id", required = false) Integer task_id,
                                 @ApiParam("用户di") @RequestParam(value = "user_id", required = false) Integer user_id,
                                 @ApiParam("任务完成状态") @RequestParam(value = "tasklist_status", required = false) Integer tasklist_status,
                                 @ApiParam("任务更多") @RequestParam(value = "tasklist_more1", required = false) String tasklist_more1
    ) throws Exception {
        BaseModel model = new BaseModel();
        Tasklist tasklist = new Tasklist();
        tasklist.setTask_id(task_id);
        tasklist.setUser_id(user_id);
        tasklist.setTasklist_status(tasklist_status);
        tasklist.setTasklist_more1(tasklist_more1);
        tasklistService.queryall(tasklist, model);
        return model;
    }
}
